var notifications_per_page = 12;
var num_pages = Math.ceil(notifications.length / notifications_per_page);
var default_page = 1;
if(num_pages == 0){
	num_pages = 1;
}


function date_format(date){
	return date.substr(8, 2) + "/" + date.substr(5, 2) + "/" + date.substr(0, 4);
}
	
function displayPage(page){			
	var html = '<ul>';
	var is_new = '';
	for (var i = 0; i < notifications_per_page; i++){
		var counter = ((page - 1) * notifications_per_page) + i;
		
		if (typeof(notifications[counter]) == "undefined"){
			if(html == '<ul>'){
				html = '<br /><span class="medium-text">No Notifications found!<br /><br /></span>';
			}
			break;
		}
		
		var date = date_format(notifications[counter].date_created.substr(0, 10));
		
		if(is_new != date){
			html += '</ul>';
			html += '<span class="medium-text">' + date + '</span><br />';
			html += '<ul>';
			is_new = date;
		}
			
		html += '<li class="normal-text">';
		if(notifications[counter].is_new == 1){
			html += '<span style="color: red;"> New! </span>&nbsp&nbsp';
		}
		html += notifications[counter].message;
		html += '</li>';
	}
	html += '</ul>';
	$("#notification-list").html(html);		
}


$("#paginator").paginate({
	count: num_pages,
	start: default_page,
	display: 5,
	border: true,
	border_color: '#CD9F33',
	text_color: '#6F4632',
	background_color: '#FAF2E1',	
	border_hover_color: '#B18110',
	text_hover_color: '#6F4632',
	background_hover_color: '#DCC388', 
	images: false,
	mouse: 'press',
	onChange: function(page){
		displayPage(page);
		positionPaginator();
		replaceIdByName();
		replaceIdByPic();
	}
});

function positionPaginator(){
	var width = $('#notification-grid').width();
	var length = num_pages > 5 ? 5 : num_pages;
	var actual = 60 + 60 + 25 * num_pages;
	$('#paginator').css('margin-left', (width - actual) / 2);
}
	
$(function(){
	displayPage(default_page);
	positionPaginator();
});
